package com.sxt.bus.controller;

import com.sxt.bus.domain.Charge;
import com.sxt.bus.service.ChargeRuleService;
import com.sxt.bus.service.ChargeService;
import com.sxt.bus.vo.ChargeVo;
import com.sxt.sys.constant.SYSConstant;
import com.sxt.sys.utils.ResultObj;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @author WanMing
 * @date 2019/2/10 20:28
 */

@Controller
@RequestMapping("charge")
public class ChargeController {

    @Autowired
    private ChargeService chargeService;

    @Autowired
    private ChargeRuleService chargeRuleService;

    /**
     * 跳转到显示页面
     * @return
     */
    @RequestMapping("toUpdateCharge")
    public String toUpdateCharge(){
        return "business/updateCharge";
    }

    /**
     * 加载数据
     * @param chargeVo
     *
     * @return
     */
    @RequestMapping("loadAllCharge")
    @ResponseBody
    public List<Charge> loadAllCharge(ChargeVo chargeVo){

        List<Charge> charges = chargeService.queryAllCharge(chargeVo);
        return charges;

    }

    /**
     * 修改
     * @param chargeVo
     * @return
     */
    @RequestMapping("updateCharge")
    @ResponseBody
    public ResultObj updateCharge(ChargeVo chargeVo){
        ResultObj resultObj = null;
        try {
            chargeService.updateCharge(chargeVo);
            resultObj = new ResultObj(SYSConstant.SUCCESS_CODE,SYSConstant.UPDATE_SUCCESS);
        } catch (Exception e) {
            e.printStackTrace();
            resultObj = new ResultObj(SYSConstant.ERROR_CODE,SYSConstant.UPDATE_ERROR);
        }
        return  resultObj;
    }
}
